package conexion;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;

public class SinAsignar {

	public static void listaSinAsignar(){
		System.out.println("lista de la compra");
		URL urlListaCompra;
		HttpsURLConnection connectionListaCompra = null;
		String lineListaCompra="0";
		String setCookie = Conexion.EASW_KEY + "; " + Conexion.easf_sess_com + "; FUTWebPhishing" + Conexion.FUTWebPhishing;
		try{
			urlListaCompra = new URL("https://utas.fut.ea.com/ut/game/fifa13/purchased/items");
			connectionListaCompra = (HttpsURLConnection)urlListaCompra.openConnection();
			connectionListaCompra.setRequestMethod("POST");
			connectionListaCompra.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31");
			connectionListaCompra.setRequestProperty("Cookie", setCookie);
			connectionListaCompra.setRequestProperty("Content-Type", "application/json");       
			connectionListaCompra.setRequestProperty("X-UT-SID", Conexion.XUTSID);       
			connectionListaCompra.setRequestProperty("X-HTTP-Method-Override", "GET");
			connectionListaCompra.setUseCaches (false);connectionListaCompra.setDoInput(true);connectionListaCompra.setDoOutput(true);          
			                                      
			//Get Response  
			InputStream isListaCompra = connectionListaCompra.getInputStream();             
			BufferedReader rdListaCompra = new BufferedReader(new InputStreamReader(isListaCompra));                
			lineListaCompra = rdListaCompra.readLine();
			String lineListaCompra2 = lineListaCompra;
			System.out.println("\n"+lineListaCompra);
			
			int contador=0;		
			
			while (lineListaCompra.indexOf("itemData") > -1) {
				lineListaCompra = lineListaCompra.substring(lineListaCompra.indexOf("itemData")+"itemData".length(),lineListaCompra.length());
				contador++; 
			}

			for(int x=0;x<30;x++){
				String itemIdPurchase = JsonParse.itemIdPurchase(lineListaCompra2, x);
				System.out.println("Pasar a mazo de cambio: "+itemIdPurchase);
				MoverContrato.moverContrato(itemIdPurchase);
			}               
			
		}catch(Exception e){}
	}

}
